package bid.yanhj.radiobutton.radiobutton;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.RadioGroup;

public class MainActivity extends AppCompatActivity implements RadioGroup.OnCheckedChangeListener {

    private RadioGroup rg;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        rg = findViewById(R.id.radioGroup);

        /**
         * 实现RadioGroup监听事件
         */
        rg.setOnCheckedChangeListener(this);
    }

    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        switch (checkedId) {
            case R.id.radio1:
                Log.i("tag", "onCheckedChanged: 当前男孩");
                break;
            case R.id.radio2:
                Log.i("tag", "onCheckedChanged: 当前女孩");
                break;
            default:
        }
    }
}
